<?php
/**
 * 缓存助手类
 */
class CacheHelper extends YucyAbsHelper
{

    /**
     * 是否连接
     * @var string
     * @access protected
     */
    protected $connected;


    /**
     * 缓存存储前缀
     * @var string
     * @access protected
     */
    protected $prefix='~@';

    /**
     * 缓存连接参数
     * @var integer
     * @access protected
     */
    protected $options = array();

    /**
     * 缓存类型
     * @var string
     * @access protected
     */
    protected $type;

    /**
     * 缓存过期时间
     * @var integer
     * @access protected
     */
    protected $expire;

    
    public function __get($name) 
    {
        return $this->get($name);
    }

    
    public function __set($name, $value)
    {
        return $this->set($name, $value);
    }

    
    public function __unset($name)
    {
        $this->delete($name);
    }
    
    
    public function clear(){}
    
    
    public function setOptions($name, $value)
    {
        $this->options[$name] = $value;
    }

    
    public function getOptions($name)
    {
        return $this->options[$name];
    }
    
    
    public function getType()
    {
    	return $this->type;
    }
    
    
    /**
     * 
     * 取得缓存类实例
     * 
     * @static
     * @access public
     * @param $config array('type'=>'file', 'options' = array())
     * @return mixed
     */
    public static function factory($config)
    {
       	if (empty($config['type'])) throw new YucyException('没有指定需要的缓存类型');
       
        $class_name = ucfirst(strtolower($config['type'])) . 'Cache';
        require_once 'Cache' . DS . $class_name. '.php';
        if (!class_exists($class_name)) throw new YucyException('缓存类型不存在'.':'.$config['type']);

        return new $class_name($config['options']);
    }

    
    // 读取缓存次数
    public function Q($times='')
    {
        static $_times = 0;
        if(empty($times))
            return $_times;
        else
            $_times++;
    }

    
    // 写入缓存次数
    public  function W($times='')
    {
        static $_times = 0;
        if(empty($times))
            return $_times;
        else
            $_times++;
    }
}
?>